package main

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

var min int
var prev *TreeNode

func minDiffInBST(root *TreeNode) int {
	min = 1<<32 - 1
	prev = nil
	traverse(root)
	return min
}

func traverse(root *TreeNode) {
	if root == nil {
		return
	}
	traverse(root.Left)
	if prev != nil {
		diff := root.Val - prev.Val
		if diff < min {
			min = diff
		}
	}
	prev = root
	traverse(root.Right)
}

func main() {
}
